home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / hpgl2ps.zip / GETVAL.C < prev    next >
C/C++ Source or Header  |  1989-08-08  |  1KB  |  55 lines

  1. /* getval.c
  2.  * Returns a real number 
  3.  */
  4.  
  5. #include "defn.h"
  6.  
  7. #define ERROR "Two or more decimal places in a number"
  8.  
  9. float
  10. getval()
  11. {
  12.     char    valbuf[10];
  13.     float   value;
  14.     int     DECIMAL = 0;
  15.     int     i;
  16.  
  17.     /* Null the value buffer "valbuf" */
  18.     for (i = 0; i < 10; i++)
  19.     valbuf[i] = NULL;
  20.  
  21.     i = 0;
  22.  
  23.     ch = getc(stream);
  24.  
  25.     while ((ch == ' ') || (ch == ','))
  26.     ch = getc(stream);
  27.  
  28.     while ((ch >= '0' && ch <= '9') || ch == '.' || ch == '-' || ch == '+')
  29.     {
  30.     if (ch == '.')
  31.     {
  32.         if (DECIMAL)
  33.         {
  34.         fprintf(stderr,"Error: %s\n", ERROR);
  35.         exit(1);
  36.         }
  37.         DECIMAL = 1;
  38.     }
  39.     valbuf[i++] = ch;
  40.     ch = getc(stream);
  41.     }
  42.     /* remove trailing space or comma to set-up for 
  43.        next digit or mnemonic */
  44.     /* added by Gordon Jacobs so that definition of 
  45.        SIGNED_NUMERIC in defn.h could be made more accurate.
  46.        Solves problem of commands like PA,PD0,0... where
  47.        optional comma is present.  (Tektronix scope outputs!) */ 
  48.     while ((ch == ' ') || (ch == ','))
  49.     ch = getc(stream);
  50.  
  51.     ungetc(ch, stream);        /* Put non numeric char back */
  52.     value = atof (valbuf);
  53.     return (value);
  54. }
  55.